void decode_current(int * value, int N,  FILE * file)
{
  int ones = 0, iter, tmp = 0, bits,q,r = 0;
  *value = 0;
  for(iter=0;1;iter ++)
    {
      read_bit(&tmp,file);
      if(tmp&1)
	ones++;
      else
	{
	  q = ones;
	  break;
	}
    }
  if(N>1)
    // If N==1 then the r==0. The encoder should have not
    //encoded this, since it is redundant.
    {
      bits = log2_ceil(N);
      for(iter=0;iter<(bits-1);iter++)
	read_bit(&r,file);
      if(r>=((1<<bits)-N))
	read_bit(&r,file);
    }
  *value = q*N + r;
}


void decode_egk(int * value, int m,  FILE * file)
{// error should always be less or equal than m
    int ones = 0, iter, tmp = 0, bits,q,r = 0;
    *value = 0;
      read_bit(&tmp,file);
      if(!(tmp&1))
	*value=m;
      else
	{
        if (m<0)
             printf("decode_egk\n");
	bits = log2_ceil(m);
        for(iter=0;iter<(bits-1);iter++)
            read_bit(&r,file);
        if(r>=((1<<bits)-m))
            read_bit(&r,file);
        *value = r;
	}
}

void plain_decode(int * value, FILE * file){
    int iter,r=0;
    for(iter=0;iter<8;iter++)
	read_bit(&r,file);
    *value=r;
}
